package com.weng.coder.service;

import java.beans.Transient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.coder.entity.Field;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.weng.coder.mapper.ColumnMapper;
import com.weng.coder.entity.Column;
import org.springframework.transaction.annotation.Transactional;


/**
 * 列 业务实现类
 *
 * @作者 wengzhonghui
 * @创建时间 2018-02-24 20:18:16
 */
@Service("columnService")
public class ColumnServiceImpl implements ColumnService {
	@Resource
	private ColumnMapper columnDao;
	
	
	public List<Column> findByIds(List<String> ids){
		return columnDao.selectBatchIds(ids);
			}
	/**
	 * Save
	 * @param t
	 */
	@Transactional
	@Override
	public Column save(Column t) {
			if(StringUtils.isEmpty(t.getId())){
					columnDao.insert(t);
			}else{
					columnDao.updateById(t);
			}
		return t;
	}

	@Override
	public void delete(String id) {
		columnDao.deleteById(id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public IPage<Column> getDataByPage(int pageNo, int pageSize, Column t) {

		QueryWrapper<Column> qw = new QueryWrapper<>();
		if(!StringUtils.isEmpty(t.getCode())) qw.eq("CODE", t.getCode());
		if(!StringUtils.isEmpty(t.getTableId())) qw.eq("TABLE_ID", t.getTableId());
		IPage<Column> page = new PageModel<>(pageNo,pageSize);
		return this.columnDao.selectPage(page, qw);
	}

	public void deleteByTableId(String tableId){
		QueryWrapper<Column> qw = new QueryWrapper<>();
		qw.eq("TABLE_ID", tableId);
		columnDao.delete(qw);
	}
	

	@Override
	public void delete(Column t) {
		columnDao.deleteById(t.getId());
	}
	

	@Override
	public Column getOne(String id) {
		return columnDao.selectById(id);
	}

	@Override
	public boolean exists(String id) {
		return getOne(id) != null;
	}

	@Override
	public void delete(Iterable<Column> entities) {
		if(entities!=null){
			for(Column t:entities){
				columnDao.deleteById(t.getId());
			}
		}
	}

	@Override
	public void deleteByIds(String[] ids) {
		if(ids!=null && ids.length>0){
			for(String id:ids){
				columnDao.deleteById(id);
			}
		}
	}
	
	
}
